package edu.nf.vrs.vaccination.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Author: @Wai
 * Date: 2022-3-30
 */
@Configuration
public class RabbitMQConfig {
    public static final String EXCHANGE_NAME = "needleNum.exchange";
    public static final String QUEUE_NAME = "needleNum.queue";
    public static final String ROUTER = "es";

    /**
     * 装配Topic类型的Exchange
     * 也可以装配其他类型如：DirectExchange、FanoutExchange
     * TopicExchange构造方法第一个参数指定交换机名称，第二个参数是否持久化交换机，
     * 第三个参数是否自动删除交换机
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(EXCHANGE_NAME, false, false);
    }

    @Bean
    public Queue queue() {
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(topicExchange()).with(ROUTER);
    }
}